package cn.rengy.web.framework.wxmp.material;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.rengy.tpa.wxmp.material.MaterialManager;
import cn.rengy.tpa.wxmp.token.AccessToken;
import cn.rengy.web.framework.sql.DbService;
import cn.rengy.web.framework.wxmp.token.AccessTokenCacheService;
@Service
public class MaterialService {
	@Autowired
	private DbService dbService;
	@Autowired
	private AccessTokenCacheService accessTokenCacheService;
	@Transactional(rollbackFor=Exception.class)
	public void pull() throws Exception{
		String appid=null;
		AccessToken accessToken=accessTokenCacheService.getAccessToken(appid);
		MaterialManager materialManager = new MaterialManager(accessToken);
		this.dbService.updateBeanParameter("delete_all_material", appid);
		List<Map<String,Object>> list=materialManager.allMaterial();
		
		if(list!=null&&list.size()>0){
			this.dbService.batchUpdate("grid_103_wx_material-insert", list.toArray(new Map[list.size()]));
			list.clear();
		}
	}
}
